package org.exia.minisig.swing.view.common;

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.exia.minisig.model.object.DescriptibleElement;
import org.exia.minisig.swing.view.home.HomeFram;

@SuppressWarnings("serial")
public class ResultList extends JPanel {
	//VAR
	private JPanel panelContenu;
	private MiniSIGSwing parent;
	ArrayList<DescriptibleElement> childList;
	//GET & SET
	public MiniSIGSwing getParen(){
		return parent;
	}
	public void setParent(MiniSIGSwing parent) {
		this.parent = parent;
	}
	//CONSTRUCTOR
	public ResultList(MiniSIGSwing _parent, ArrayList<DescriptibleElement> _element){
		initializeVar(_parent, _element);
	}
	public void initializeVar(MiniSIGSwing _parent, ArrayList<DescriptibleElement> _element){
		
		this.childList = _element;
		//-----------------------------------------------------------//
		this.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
		//-----------------------------------------------------------//
		this.parent = _parent;
		//
		JPanel scrollPanel = new JPanel(new BorderLayout(1,0));
		
		this.setLayout(new BorderLayout(0,0));
		
		panelContenu = new JPanel();
		panelContenu.setLayout(new BoxLayout(panelContenu, BoxLayout.Y_AXIS));
		
        
        scrollPanel.setBackground(Color.white);
        
        
        
        this.add(new JScrollPane(scrollPanel), BorderLayout.CENTER);
        panelContenu.setBackground(Color.orange);
        scrollPanel.add(panelContenu, BorderLayout.NORTH);
        scrollPanel.add(new JLabel(" "), BorderLayout.CENTER);
        
        //Construction du panel
        for (DescriptibleElement element : this.childList) {
			this.addPanel(new ResultItem(this, element));
		}
        
        scrollPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        panelContenu.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
	}
	//METHODE
	public void addPanel(ResultItem item){
		this.panelContenu.add(item);
		this.revalidate();
	}
	public void childClicked(ResultItem item){
		parent.setSelectedElement(item.getCurrentElement());
	}
	
}
